package com.ruoyi.project.system.service.impl;

import java.util.List;

import com.ruoyi.common.exception.CustomException;
import com.ruoyi.project.system.domain.CourseCatalog;
import com.ruoyi.project.system.mapper.CourseCatalogMapper;
import com.ruoyi.project.system.service.ICourseCatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 课程章节Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-10-07
 */
@Service
public class CourseCatalogServiceImpl implements ICourseCatalogService
{
    @Autowired
    private CourseCatalogMapper courseCatalogMapper;

    /**
     * 查询课程章节
     * 
     * @param id 课程章节ID
     * @return 课程章节
     */
    @Override
    public CourseCatalog selectCourseCatalogById(Integer id)
    {
        return courseCatalogMapper.selectCourseCatalogById(id);
    }

    /**
     * 查询课程章节列表
     * 
     * @param courseCatalog 课程章节
     * @return 课程章节
     */
    @Override
    public List<CourseCatalog> selectCourseCatalogList(CourseCatalog courseCatalog)
    {
        return courseCatalogMapper.selectCourseCatalogList(courseCatalog);
    }

    /**
     * 新增课程章节
     * 
     * @param courseCatalog 课程章节
     * @return 结果
     */
    @Override
    public int insertCourseCatalog(CourseCatalog courseCatalog)
    {

        CourseCatalog course =  courseCatalogMapper.selectName(courseCatalog.getName());
        if(course!=null){
            throw new CustomException("新增失败,存在相同的章节名称");
        }
        return courseCatalogMapper.insertCourseCatalog(courseCatalog);
    }

    /**
     * 修改课程章节
     * 
     * @param courseCatalog 课程章节
     * @return 结果
     */
    @Override
    public int updateCourseCatalog(CourseCatalog courseCatalog)
    {
        return courseCatalogMapper.updateCourseCatalog(courseCatalog);
    }

    /**
     * 批量删除课程章节
     * 
     * @param ids 需要删除的课程章节ID
     * @return 结果
     */
    @Override
    public int deleteCourseCatalogByIds(Integer[] ids)
    {
        return courseCatalogMapper.deleteCourseCatalogByIds(ids);
    }

    /**
     * 删除课程章节信息
     * 
     * @param id 课程章节ID
     * @return 结果
     */
    @Override
    public int deleteCourseCatalogById(Integer id)
    {
        return courseCatalogMapper.deleteCourseCatalogById(id);
    }
}
